﻿using System.Linq;
using System.Web.Mvc;
using Pyramid.Models;

namespace Pyramid.Bll
{
	public class SelectListHelper : BllBase
	{
		public static SelectListHelper NewInstance
		{
			get { return new SelectListHelper(); }
		}

		/// <summary>
		/// 财务收款项目列表
		/// </summary>
		public SelectList FinanceProjects(PayerTypes payerType, object selectedItem = null, bool insertHeader = false)
		{
			var projects = Db.FinanceProjects.Where(x => x.PayerType == (int) payerType).ToList()
				.Select(x => new SelectListItem {Text = x.Name, Value = string.Format("{0}", x.Id)})
				.ToList();

			if (insertHeader)
			{
				projects.Insert(0, new SelectListItem {Text = "==所有项目==", Value = ""});
			}
			return new SelectList(projects, "Value", "Text", selectedItem);
		}

		/// <summary>
		/// 区域选项列表
		/// </summary>
		public SelectList MarketZones(object selectedItem = null, bool insertHeader = false)
		{
			var markets = Db.MarketZones.ToList()
				.Select(x => new SelectListItem {Text = x.ZoneName, Value = string.Format("{0}", x.ZoneId)})
				.ToList();
			if (insertHeader)
			{
				markets.Insert(0, new SelectListItem {Text = "==所有区域==", Value = ""});
			}
			return new SelectList(markets, "Value", "Text", selectedItem);
		}

		/// <summary>
		/// 部门列表
		/// </summary>
		public SelectList Departments(object selectedItem = null, bool insertHeader = false)
		{
			var departments = Db.Departments.ToList().Select(x => new SelectListItem {Text = x.Name, Value = string.Format("{0}", x.Id)}).ToList();
			if (insertHeader)
			{
				departments.Insert(0, new SelectListItem {Text = "==所有部门==", Value = ""});
			}
			return new SelectList(departments, "Value", "Text", selectedItem);
		}

		/// <summary>
		/// 员工职位列表
		/// </summary>
		public SelectList StaffPositions(object selectedItem = null, bool insertHeader = false)
		{
			var positions = Db.StaffPositions.ToList().Select(x => new SelectListItem {Text = x.Name, Value = string.Format("{0}", x.Id)}).ToList();
			if (insertHeader)
			{
				positions.Insert(0, new SelectListItem {Text = "==所有职位==", Value = ""});
			}
			return new SelectList(positions, "Value", "Text", selectedItem);
		}
	}
}